﻿@using KRM.Core

@using KRM.Core.Library
@model KRM.Core.Task
@{
    ViewBag.Title = "View Task";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
}

<div id="addfinalcomment" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="viewtrigger" aria-hidden="true">
    <form action="/orderview/addfinalcomment" method="POST">
        <input type="hidden" name="taskid" value="@Model.TaskID"/>
        <input type="hidden" name="orderref" value="@ViewBag.OrderRef"/>
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5 id="myModalLabel">Add final comment</h5>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span2">Result</div>
                <div class="span8">
                    @Html.DropDownList("ResultID")
                </div>
            </div>

            <div class="row-fluid">
                <p><strong>Comment</strong></p>
                <textarea rows="5" style="width: 96%" name="comment">@Model.FinalComments</textarea>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary">Update</button>
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </form>
</div>
<div id="reassign" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="viewtrigger" aria-hidden="true">
    <form action="/orderview/reassignuser" method="POST">
        <input type="hidden" name="taskid" value="@Model.TaskID"/>
        <input type="hidden" name="orderref" value="@ViewBag.OrderRef"/>
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5>Assign task to which user</h5>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span3">User</div>
                <div class="span8">
                    @Html.DropDownList("UserId")
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary">Assign!</button>
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </form>
</div>
<div style="padding: 10px">
    @if (Request["msg"] != null && Request["msg"] != "success")
    {
        <div class="alert alert-error">
            <strong>Error.</strong> @Request["msg"]
        </div>
    }
    @Html.Partial("Partial/_MessageResult")
    <div class="row-fluid">
        <div class="span2">Status:</div>
        <div class="span2">
            @switch (Model.Status)
            {
                case "Assigned":
                <span class="label label-warning">@Model.Status</span> break;
                case "Started":
                <span class="label label-info">@Model.Status</span> break;
                case "Completed":
                <span class="label label-success">@Model.Status</span> break;
                default:
                <span class="label">@Model.Status</span> break;
            }
        </div>
        <div class="span2">Complete By: </div>
        <div class="span4"><strong>@String.Format("{0:dddd, MMMM d, yyyy}", Model.CompleteByDate)</strong></div>
    </div>
    <div class="row-fluid">
        <div class="span2">Priority:</div>
        <div class="span2">
            @switch (Model.Priority)
            {
                case "Urgent":
                <span class="label" style="background: red">@Model.Priority</span> break;
                case "High":
                <span class="label label-important">@Model.Priority</span> break;
                case "Normal":
                <span class="label label-warning">@Model.Priority</span> break;
                case "Low":
                <span class="label">@Model.Priority</span> break;
            }
        </div>
        <div class="span2">Duration: </div>
        <div class="span2"><strong>@Model.Duration</strong></div>
        <div class="span1">TaskID: </div>
        <div class="span2">@Model.TaskID</div>
    </div>
    <div class="task-panel">
        <div class="row-fluid">
            <div class="span2">Type:</div>
            <div class="span4">
                <strong style="color: red">@Model.Type</strong>
            </div>
            <div class="span2">OrderRef:</div>
            <div class="span3"><strong style="color: red">@ViewBag.OrderRef</strong></div>
        </div>
        <div class="row-fluid" style="margin-bottom: 10px">
            <div class="span2">Title</div>
            <div class="span4">
                <strong style="color: red">@Model.Title</strong>
            </div>
            <div class="span3"><a href="/orderview/orderdetail?orderref=@ViewBag.OrderRef" target="_blank" class="btn btn-info">View Order</a></div>
            <div class="span3">
                @if (Model.Status == "Assigned" || Model.Status == "Unassigned")
                {
                    if (ViewBag.Owned)
                    {
                    <form action="/orderview/starttask" method="POST" class="nomargin">
                        <input type="hidden" name="taskid" value="@Model.TaskID"/>
                        <input type="hidden" name="orderref" value="@ViewBag.OrderRef"/>
                        <button class="btn btn-danger" type="submit" onclick="return confirm('Are you sure, you want to start this Task?');"><strong>Start</strong></button>
                    </form>
                    }
                    else
                    {
                    <form action="/orderview/retrievetask" method="POST" class="nomargin" id="frRetrievetask">
                        <input type="hidden" name="taskid" value="@Model.TaskID"/>
                        <input type="hidden" name="orderref" value="@ViewBag.OrderRef"/>
                        <button class="btn btn-danger" type="button" onclick ="if(confirm('TASK NO: @Model.TaskID \r\nAre you sure, you want to Retrieve this Task?')){$('#frRetrievetask').submit();}"><strong>Retrieve Task!</strong></button>
                    </form>
                    }

                }
            </div>
        </div>
        <div class="row-fluid">
            <div class="span2">Reason</div>
            <div class="span4">
                <strong style="color: red">@Model.Reason</strong>
            </div>
            <div class="span3">
                @{
                    var ticket = Model.ParentTicket;
                    if (ticket!=null)
                    {
                      <a href="/ticket/viewticket/@Model.ParentTicket.TicketID" target="_blank" class="btn btn-info">View Ticket</a>
                    }
                }
            </div>
        </div>
        <div class="row-fluid">
            <div class="span2">Description</div>
            <div class="span8">
                <div style="padding: 5px 10px; background: white; height: 70px; overflow: auto; margin-bottom: 10px; font-size: 11px">@Html.Raw((Model.TaskDescription != null ? Model.TaskDescription.Replace("\r\n", "<br>") : ""))</div>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span2">Result:</div>
            <div class="span8">
                <strong style="color: red">@Model.Result</strong>
            </div>
            @if (Model.Status == "On Hold" || Model.Status == "Started")
            {
                if (ViewBag.Owned)
                {
                <div class="span2">
                    <button class="btn btn-warning" data-toggle="modal" href="#addfinalcomment"><strong>Add final comments!</strong></button>
                </div>
                }
            }

        </div>
        <div class="row-fluid">
            <div class="span2">Final Comments</div>
            <div class="span8">
                <div style="padding: 5px 10px; background: white; height: 70px; overflow: auto; margin-bottom: 10px; font-size: 11px">@Html.Raw((Model.FinalComments != null ? Model.FinalComments.Replace("\r\n", "<br>") : ""))</div>
            </div>
            <br />
            @if (Model.Status == "On Hold" || Model.Status == "Started")
            {
                if (ViewBag.Owned)
                {
                <form action="/orderview/completetask" method="POST" class="nomargin span2">
                    <input type="hidden" name="taskid" value="@Model.TaskID"/>
                    <input type="hidden" name="orderref" value="@ViewBag.OrderRef"/>
                    <button class="btn btn-warning" type="submit"><strong>Complete task!</strong></button>
                </form>
                }
            }
        </div>
        <div class="row-fluid">
            <div class="span3">Complete by user:</div>
            <div class="span3">
                <strong>@Model.CompleteByUserName</strong>
            </div>
            <div class="span1">Date:</div>
            <div class="span4">@String.Format("{0:dddd, MMMM d, yyyy}", Model.CompletedDate)</div>
        </div>
        <div class="row-fluid">
            <div class="span2">Assigned To:</div>
            <div class="span7">
                <strong>@Model.AssignedToUserName</strong>
            </div>
            @if ((ViewBag.Owned || Users.Current(User.Identity.Name).HasPermission(Permissions.CanReassignTaskNotOwner)) && (Model.Status == "Assigned" || Model.Status == "Unassigned" || Model.Status == "Started"))
            {
                if (Users.Current(User.Identity.Name).HasPermission(Permissions.TasksCanReassign) || Users.Current(User.Identity.Name).HasPermission(Permissions.CanReassignTaskNotOwner))
                {
                    <div class="span3">
                        <a class="btn btn-warning" data-toggle="modal" href="#reassign"><strong>Re-assign!</strong></a>
                    </div>
                }
            }
            else
            {
                <div class="span3">
                    <a class="btn btn-warning" onclick="alert('You cannot re-assign this task. The Tasks Details may have been changed!');"><strong>Re-assign!</strong></a>
                </div>
            }
        </div>
        @if (Model.AssignedToUser == 267)
        {
            <div class="row-fluid">
                <div class="span2">Order Status:</div>
                <div class="span3">@ViewBag.OrderStatus</div>
                <div class="span3 text-right">Refund Reason:</div>
                <div class="span4">@ViewBag.RefundReason</div>
            </div>
        }
        @if (Model.AssignedToUser == 754)
        {
            <div class="row-fluid">
                <div class="span2">Agents Issue:</div>
                <div class="span3">@ViewBag.AgentsIssue</div>
                <div class="span3 text-right">Trigger Statement:</div>
                <div class="span4">@ViewBag.TriggerStatement</div>
            </div>
            <div class="row-fluid">
                <div class="span3">Resolutions Team - Disposition:</div>
                <div class="span4">@ViewBag.Disposition</div>
            </div>
        }
        
        <div class="row-fluid">
            <div class="span2">Assigned By:</div>
            <div class="span3">
                <strong>@Model.AssignedByUserName</strong>
            </div>
            <div class="span3">Assigned on Date:</div>
            <div class="span4">@String.Format("{0:dddd, MMMM d, yyyy}", Model.AssignedDate)</div>
        </div>
    </div>

    <div class="row-fluid">
        <div class="span5">
        </div>
        <div class="span6 text-right">
            <button class="btn btn-primary" onclick=" javascript:window.close(); ">Close</button>
        </div>
    </div>
</div>
